﻿using UnityEngine;
using System.Collections;

public class ArmoryLabel : MonoBehaviour {

    public int m_iIndex ;  // 위치 인덱스

	// Use this for initialization
	void Start () {

        GetComponent<UILabel>().depth = transform.parent.parent.parent.GetComponent<UISprite>().depth - 1;
        transform.localPosition = new Vector3(-25, 41.3f - 6.0f * m_iIndex);
        transform.localScale = new Vector3(0.095f, 0.13f);

        GetComponent<UILabel>().text = GameObject.Find("ArmoryPaper").GetComponent<ArmoryPaper>().m_WeaponGroupList[m_iIndex].m_WpnData.m_strWeaponName;
        
	}
	
	// Update is called once per frame
	void Update () {
        transform.FindChild("LabelCount").GetComponent<UILabel>().text = string.Format("{0}", GameObject.Find("ArmoryPaper").GetComponent<ArmoryPaper>().m_WeaponGroupList[m_iIndex].m_iNumberOfWpn);
	}

    void OnClick()
    {
            GameObject.Find("ArmoryPaper").GetComponent<ArmoryPaper>().m_SelectedWeapon = GameObject.Find("ArmoryPaper").GetComponent<ArmoryPaper>().m_WeaponGroupList[m_iIndex].m_WpnData;
            transform.parent.parent.Find("SelectedArm").GetComponent<UISprite>().enabled = true;
            transform.parent.parent.Find("SelectedArm").localPosition = transform.localPosition;

            GameObject.Find("MainCamera").GetComponent<AudioSource>().PlayOneShot(Resources.Load<AudioClip>("Audio/Click"));
    }

    void OnHover(bool isOver)
    {
        if (isOver)
        {
            transform.parent.parent.Find("HoveredArm").GetComponent<UISprite>().enabled = true;
            transform.parent.parent.Find("HoveredArm").localPosition = transform.localPosition;
        }
        else
        {
            transform.parent.parent.Find("HoveredArm").GetComponent<UISprite>().enabled = false;
        }
    
    }
}
